from peewee import AutoField, CharField, BooleanField, BigIntegerField, TextField
from common.model.abstrct import AbstractModel, IntEnumField, AbstractModelWithID
from enums.pay_enum import PayWayStatusEnum


class TotalPayWay(AbstractModel):

    class Meta:
        table_name = "tb_pay_way"
        indexes = (
            (("code", ), True),
        )
    pay_way_id = AutoField(primary_key=True)
    name = CharField(max_length=16, help_text="支付方式的名字")
    code = CharField(max_length=8, help_text="支付方式唯一编码")
    status = IntEnumField(help_text="支付方式可用状态", choices=PayWayStatusEnum, default=PayWayStatusEnum.enable)
    need_audit = BooleanField(help_text="是否需要审核", default=False)


class TenantAliPayConfig(AbstractModelWithID):

    class Meta:
        table_name = "tb_tenant_ali_pay_config"
        indexes = (
            (("tenant_id", "appid"), True),
            (("appid", ), False),
        )

    tenant_id = BigIntegerField(help_text="租户id")
    appid = CharField(help_text="支付宝的appid")
    app_private_key = TextField(help_text="商户私钥,最好是做对称加密处理入库")
    ali_public_key = TextField(help_text="阿里公钥,最好是做对称加密处理入库")
    domain = CharField(default="https://openapi.alipay.com/gateway.do", help_text="阿里接口地址,默认是正式环境")
    encrypt_type = CharField(max_length=16, help_text="加密方式", null=True)
    encrypt_key = CharField(max_length=64, help_text="加密密钥", null=True)
    return_url = TextField(null=True, help_text="return url")
    notify_url = TextField(help_text="支付/退款回调地址自动生成")
    sign_type = CharField(default="RSA2", help_text="加签方式")
    charset = CharField(default="utf-8", help_text="编码格式")
